﻿Public Class FrmModificarMaquina

    Private Sub btnCancelar_Click(sender As Object, e As EventArgs) Handles btnCancelar.Click
        frmTransparente.Close()
        Me.Hide()
    End Sub

    Private Sub picBoxBack_Click(sender As Object, e As EventArgs)
        frmTransparente.Close()
        Me.Hide()
    End Sub

    Private Sub UserControl_Initialize(sender As Object, e As EventArgs) Handles Me.Load
        For Each form As FrmConsultarMaquina In FrmPrincipal.paneForm.Controls.OfType(Of FrmConsultarMaquina)()
            txtId.Text = form.maquinaXModificar.Id
            txtNombre.Text = form.maquinaXModificar.Nombre
            txtNumMaquina.Text = form.maquinaXModificar.NumMaquina
            txtNumActivo.Text = form.maquinaXModificar.NumActivo
            If form.maquinaXModificar.Estado Then
                cmbEstado.SelectedIndex = 0
            Else
                cmbEstado.SelectedIndex = 1
            End If
        Next
    End Sub

    Private Sub btnModificar_Click(sender As Object, e As EventArgs) Handles btnModificar.Click
        Dim id As Int32 = CInt(Me.txtId.Text)
        Dim nombre As String = Me.txtNombre.Text()
        Dim numMaquina As String = Me.txtNumMaquina.Text
        Dim numActivo As String = Me.txtNumActivo.Text
        Dim estado As Boolean
        lblNombreReq.Visible = False
        lblNumMaqReq.Visible = False
        lblNumActReq.Visible = False

        If cmbEstado.SelectedIndex = 0 Then
            estado = True
        ElseIf cmbEstado.SelectedIndex = 1 Then
            estado = False
        End If

        If txtNombre.Text = "" Then
            lblNombreReq.Visible = True
        End If

        If txtNumMaquina.Text = "" Then
            lblNumMaqReq.Visible = True
        End If

        If txtNumActivo.Text = "" Then
            lblNumActReq.Visible = True
        End If

        If txtNombre.Text <> "" And txtNumMaquina.Text <> "" And txtNumActivo.Text <> "" Then
            objGestor.modificarMaquina(id, nombre, numMaquina, numActivo, estado)
            txtNombre.Clear()
            txtNumMaquina.Clear()
            txtNumActivo.Clear()
            cmbEstado.SelectedIndex = 0

            For Each form As FrmConsultarMaquina In FrmPrincipal.paneForm.Controls.OfType(Of FrmConsultarMaquina)()
                form.tblMaquinas.DataSource = objGestor.listarMaquinas()
            Next

            frmTransparente.Close()
        End If
    End Sub

    Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
        frmTransparente.Close()
        Me.Hide()
    End Sub
End Class
